﻿using System;
using System.Linq.Expressions;

namespace BulkUploadGovernanceFiles.MongoSpecification
{
    public class NotSpecification<T> : CompositeSpecification<T>
    {
        private readonly ISpecification<T> _other;

        public NotSpecification(ISpecification<T> other)
        {
            _other = other;
        }

        public override Expression<Func<T, bool>> SpecExpression
        {
            get
            {
                var objParam = Expression.Parameter(typeof(T), "obj");

                var newExpr = Expression.Lambda<Func<T, bool>>(Expression.Not(Expression.Invoke(_other.SpecExpression, objParam)),
                    objParam);

                return newExpr;
            }
        }
    }
}
